chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
  if (tabs && tabs[0]) {
    const currentUrl = tabs[0].url;
    // 将当前 URL、起始和结束页码传递给后台脚本
  // 假设你有一个元素来显示URL
  console.log(currentUrl)
  var urlDisplayElement = document.getElementById("template");
  if (urlDisplayElement) {
      urlDisplayElement.value = currentUrl;
  }
  }
});

document.getElementById('startDownload').addEventListener('click', () => {
    const template = document.getElementById('template').value;
    const start = parseInt(document.getElementById('start').value, 10);
    const end = parseInt(document.getElementById('end').value, 10);
  
    if (isNaN(start) || isNaN(end) || start > end) {
      alert('Invalid input. Please enter valid start and end numbers.');
      return;
    }
  
    chrome.runtime.sendMessage({
      action: 'downloadImages',
      template: template,
      start: start,
      end: end
    });
  });